<?php

/**
 *  Ini adalah project open source yang dikembangkan oleh Impossible Team
 *
 *  Copyright (c) 2011 ekoindri. <ekoindri@ekoindri.com>
 *
 *  Versi: 1.2
 *  Developed by: Impossible Team
 *  Leader: Eko Indriyawan
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *  USA
 *
 */

require_once("rpcl/rpcl.inc.php");
require_once("soap_sis_common.php");
require_once("soap_sis_common_combo.php");
  //Includes
use_unit("webservices.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

function DATA_SISWA_GURU_MAPEL(
$connection_string){
  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  $sql = "
          SELECT    ID,
                    SISWA_KODE,
                    SISWA_NAMA_AWAL,
                    SISWA_NAMA_TENGAH,
                    SISWA_NAMA_AKHIR
          FROM      TABEL_SISWA
          ORDER BY  SISWA_NAMA_AWAL ASC
          ";
  $result = mysql_query($sql);

  $numrows = mysql_num_rows($result);
  $siswalist = array();
  for($x = 0; $x < $numrows; $x++){
    $siswalist[] = mysql_fetch_array($result);
    }

  mysql_close();
  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());
  $sql = "
          SELECT    ID,
                    GURU_KODE,
                    GURU_NAMA_AWAL,
                    GURU_NAMA_TENGAH,
                    GURU_NAMA_AKHIR
          FROM      TABEL_GURU
          ORDER BY  GURU_NAMA_AWAL ASC
          ";
  $result = mysql_query($sql);
  $numrows = mysql_num_rows($result);
  $gurulist = array();
  for($x = 0; $x < $numrows; $x++){
    $gurulist[] = mysql_fetch_array($result);
    }

  mysql_close();
  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());
  $sql = "
          SELECT    ID,
                    MAPEL_KODE,
                    MAPEL_NAMA,
                    MAPEL_JENIS,
                    MAPEL_KELAS
          FROM      TABEL_MAPEL
          ORDER BY  MAPEL_NAMA ASC
          ";
  $result = mysql_query($sql);

  $numrows = mysql_num_rows($result);
  $mapellist = array();
  for($x = 0; $x < $numrows; $x++){
    $mapellist[] = mysql_fetch_array($result);
    }

  mysql_close();
  return array('Berhasil', $siswalist, $gurulist, $mapellist);
  }

function SISWA_SIMPAN_NILAI_DATASET($connection_string, $daftarnilai){

  mysql_connect($connection_string[server_host], $connection_string[server_username], $connection_string[server_password]);
  mysql_select_db($connection_string[server_database]) or die(mysql_error());

  for($x = 0; $x < 100; $x++){
    $nilai = $daftarnilai[$x];
    if($nilai[SISWA_ID] != '') {

      $query = "
            INSERT INTO TABEL_SISWA_NILAI
            (
            SISWA_ID,
            MAPEL_ID,
            GURU_ID,
            NILAI_TGL,
            NILAI_UJIAN,
            NILAI_ULANGAN,
            NILAI_PERINGKAT,
            NILAI_KETERANGAN
            )
            VALUES
            (
            '" . $nilai[SISWA_ID]         . "',
            '" . $nilai[MAPEL_ID]         . "',
            '" . $nilai[GURU_ID]          . "',
            '" . $nilai[NILAI_TGL]        . "',
            '" . $nilai[NILAI_UJIAN]      . "',
            '" . $nilai[NILAI_ULANGAN]    . "',
            '" . $nilai[NILAI_PERINGKAT]  . "',
            '" . $nilai[NILAI_KETERANGAN] . "'
            )

            ";

      return( mysql_query($query) );

      }
    }
  }

  //Class definition
class DM_ENTRY_SISWA_NILAI extends DataModule{
  public $SIS_ENTRY_SISWA_NILAI = null;
  function SIS_ENTRY_SISWA_NILAIAddComplexTypes($sender, $params){
    RegisterCommonComplexType_InfoServer($this->$SIS_ENTRY_SISWA_NILAI);
    RegisterCommonComplexType_InfoSiswa_Combo($this->$SIS_ENTRY_SISWA_NILAI);
    RegisterCommonComplexType_InfoGuru_Combo($this->$SIS_ENTRY_SISWA_NILAI);
    RegisterCommonComplexType_DataMapel_Combo($this->$SIS_ENTRY_SISWA_NILAI);
    RegisterCommonComplexType_InfoNilai($this->$SIS_ENTRY_SISWA_NILAI);
    }

  function SIS_ENTRY_SISWA_NILAIRegisterServices($sender, $params){

    $this->$SIS_ENTRY_SISWA_NILAI->register(
    "DATA_SISWA_GURU_MAPEL",
    array(
          'connection_string'=>'tns:TInfoServer'),
    array('return'    =>'xsd:string',
          'siswalist' =>'tns:TInfoDaftarSiswa',
          'gurulist'  =>'tns:TInfoDaftarGuru',
          'mapellist' =>'tns:TDataMapel')
    );

    $this->$SIS_ENTRY_SISWA_NILAI->register
    (
    "SISWA_SIMPAN_NILAI_DATASET",
    array(
          'connection_string' =>'tns:TInfoServer',
          'daftarnilai'       =>'tns:TInfoDaftarNilai'),
    array('return             '=>'xsd:string'),
    'http://localhost/'
    );

    }
  }

global $application;

global $DM_ENTRY_SISWA_NILAI;

  //Creates the form
$DM_ENTRY_SISWA_NILAI = new DM_ENTRY_SISWA_NILAI($application);

  //Read from resource file
$DM_ENTRY_SISWA_NILAI->loadResource(__FILE__);

?>